package com.example.redis.statemachine.web;

import com.example.redis.statemachine.model.OrderDTO;
import com.example.redis.statemachine.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/OrderDTO")
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 创建订单
     *
     * @return
     */
    @RequestMapping("/create")
    public String create() {
        //创建订单
        orderService.create();
        return "sucess";
    }

    /**
     * 对订单进行支付
     *
     * @param id
     * @return
     */
    @RequestMapping("/pay")
    public String pay(@RequestParam("id") Long id) {
        //对订单进行支付
        orderService.pay(id);
        return "success";
    }

    /**
     * 对订单进行发货
     *
     * @param id
     * @return
     */
    @RequestMapping("/deliver")
    public String deliver(@RequestParam("id") Long id) {
        //对订单进行确认收货
        orderService.deliver(id);
        return "success";
    }

    /**
     * 对订单进行确认收货
     *
     * @param id
     * @return
     */
    @RequestMapping("/receive")
    public String receive(@RequestParam("id") Long id) {
        //对订单进行确认收货
        orderService.receive(id);
        return "success";
    }

    /**
     * 查询状态
     *
     * @param id
     * @return
     */
    @RequestMapping("/get")
    public OrderDTO get(@RequestParam("id") Long id) {
        return orderService.getOrders().get(id);
    }
}
